export const getLocal = (name) => {
    return localStorage.getItem(name)
}

export const setLocal = (name,value) => {
    localStorage.setItem(name,value)
}
export const clearLocal = (name) => {
    localStorage.removeItem(name)
}
export const convertToGMT = (beijingTime) => {
    const gmtTime = new Date(beijingTime);
    gmtTime.setHouts(gmtTime.getHours() - 8);
    return gmtTime;
}
export function login({ account, password }) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const mockUsers = [
          { account: 'admin', password: '111', token: 'token1' },
          { account: 'user', password: '222', token: 'token2' },
        ];
        const user = mockUsers.find(
          (u) => u.account === account && u.password === password
        );
        if (user) {
          resolve({ token: user.token });
        } else {
          reject(new Error('Invalid account or password'));
        }
      }, 1000);
    });
}
  
export const dateFormat = (date, format) => {
    format = format || 'yyyy-MM-dd hh:mm:ss';
    if(date !== 'Invalid Date'){
        let o = {
            "M+":date.getMonth() + 1,
            "d+":date.getDate(),
            "h+":date.getHours(),
            "m+":date.getMinutes(),
            "s+":date.getSeconds(),
            "q+":Math.floor((date.getMonth() + 3) / 3),
            "S":date.getMilliseconds()
        };
        return o;
    }
}